﻿using AnesSystem.Controls;
using AnesSystem.Models;
using AnesSystem.Services;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels
{

    public class AnesDocSignatureCtrlViewModel : BaseViewModel<AnesDocSignatureCtrlViewModel>
    {
        #region Variables
        //麻醉医生集合 
        private List<AccountModel> _accountAnesModelList = new List<AccountModel>();


        private String _disAnesDoctorName = "";
        private String _disNurseDoctorName = "";
        private String _disCruisingNurseDoctorName = "";
        private String _disoperDoctorName = "";



        #endregion


        #region Constructor
        public AnesDocSignatureCtrlViewModel()
        {
            _disAnesDoctorName = "";
            _disNurseDoctorName = "";
            _disCruisingNurseDoctorName = "";
            _disoperDoctorName = "";
        }
        #endregion


        #region Properties
        public string DisAnesDoctorName
        {
            get
            {

                return _disAnesDoctorName;
            }

            set
            {
                _disAnesDoctorName = value;
                RaisePropertyChanged("DisAnesDoctorName");
            }
        }

        public string DisNurseDoctorName
        {
            get
            {
                if (string.IsNullOrEmpty(_disNurseDoctorName)) return "";
                return _disNurseDoctorName;
            }

            set
            {
                _disNurseDoctorName = value;
                RaisePropertyChanged("DisNurseDoctorName");
            }
        }

        public string DisCruisingNurseDoctorName
        {
            get
            {
                return _disCruisingNurseDoctorName;
            }

            set
            {
                _disCruisingNurseDoctorName = value;
                RaisePropertyChanged("DisCruisingNurseDoctorName");
            }
        }



        public string DisoperDoctorName
        {
            get
            {

                if (string.IsNullOrEmpty(_disoperDoctorName)) return "";
                return _disoperDoctorName;
            }

            set
            {
                _disoperDoctorName = value;
                RaisePropertyChanged("DisoperDoctorName");
            }
        }
        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods

        private void ConvertAnesDoctor()
        {
            _disAnesDoctorName = "";
            if (PatientLink.AnesthesiaRecord.Zmys != null && PatientLink.AnesthesiaRecord.Zmys.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Zmys));
                if (a != null) _disAnesDoctorName += a.TrueName + "(" + a.Title + ")";
            }
            else
            {
                _disAnesDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Zmys) ? "" : PatientLink.AnesthesiaRecord.Zmys;
            }
            if (PatientLink.AnesthesiaRecord.Fmys1 != null && PatientLink.AnesthesiaRecord.Fmys1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Fmys1));
                if (a != null) _disAnesDoctorName += ","+a.TrueName + "(" + a.Title + ")";
            }
            else
            {
                _disAnesDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Fmys1) ? "" : (","+PatientLink.AnesthesiaRecord.Fmys1);
            }
            if (PatientLink.AnesthesiaRecord.Fmys2 != null && PatientLink.AnesthesiaRecord.Fmys2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Fmys2));
                if (a != null) _disAnesDoctorName += ","+a.TrueName + "(" + a.Title + ")";
            }
            else
            {
                _disAnesDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Fmys2) ? "" : ("," + PatientLink.AnesthesiaRecord.Fmys2);
            }
           DisAnesDoctorName = _disAnesDoctorName;
        }
        //初始化时手术医生
        private void ConvertOperDoctor1()
        {
            _disoperDoctorName = "";
            if (PatientLink.AnesthesiaRecord.OperDoctor1 != null && PatientLink.AnesthesiaRecord.OperDoctor1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.OperDoctor1));
                if (a != null) _disoperDoctorName += a.TrueName;
            }
            else
            {
                _disoperDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.OperDoctor1) ?"": PatientLink.AnesthesiaRecord.OperDoctor1;
            }
            if (PatientLink.AnesthesiaRecord.OperDoctor1Assistant1 != null && PatientLink.AnesthesiaRecord.OperDoctor1Assistant1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.OperDoctor1Assistant1));
                if (a != null) _disoperDoctorName += ","+a.TrueName ;
            }
            else
            {
                _disoperDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.OperDoctor1Assistant1) ? "" : ("," + PatientLink.AnesthesiaRecord.OperDoctor1Assistant1);
            }
            if (PatientLink.AnesthesiaRecord.OperDoctor1Assistant2 != null && PatientLink.AnesthesiaRecord.OperDoctor1Assistant2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.OperDoctor1Assistant2));
                if (a != null) _disoperDoctorName += "," + a.TrueName ;
            }
            else
            {
                _disoperDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.OperDoctor1Assistant2) ? "" : ("," + PatientLink.AnesthesiaRecord.OperDoctor1Assistant2);
            }
            if (PatientLink.AnesthesiaRecord.OperDoctor1Assistant3 != null && PatientLink.AnesthesiaRecord.OperDoctor1Assistant3.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.OperDoctor1Assistant3));
                if (a != null) _disoperDoctorName += "," + a.TrueName ;
            }
            else
            {
                _disoperDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.OperDoctor1Assistant3) ? "" : ("," + PatientLink.AnesthesiaRecord.OperDoctor1Assistant3);
            }
            DisoperDoctorName = _disoperDoctorName;
        }



        //初始化洗手护士
        private void ConvertNurseDoctor()
        {
            _disNurseDoctorName = "";
            if (PatientLink.AnesthesiaRecord.Xshs1 != null && PatientLink.AnesthesiaRecord.Xshs1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xshs1));
                if (a != null) _disNurseDoctorName += a.TrueName;
            }
            else
            {
                _disNurseDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xshs1) ? "" : (PatientLink.AnesthesiaRecord.Xshs1);
            }
            if (PatientLink.AnesthesiaRecord.Xshs2 != null && PatientLink.AnesthesiaRecord.Xshs2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xshs2));
                if (a != null) _disNurseDoctorName +=","+ a.TrueName ;
            }
            else
            {
                _disNurseDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xshs2) ? "" : ("," + PatientLink.AnesthesiaRecord.Xshs2);
            }
            if (PatientLink.AnesthesiaRecord.Xshs3 != null && PatientLink.AnesthesiaRecord.Xshs3.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xshs3));
                if (a != null) _disNurseDoctorName += "," + a.TrueName ;
            }
            else
            {
                _disNurseDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xshs3) ? "" : ("," + PatientLink.AnesthesiaRecord.Xshs3);
            }
            DisNurseDoctorName = _disNurseDoctorName;
        }

        //初始化巡航护士
        private void ConvertCruiseNurseDoctor()
        {
            _disCruisingNurseDoctorName = "";
            if (PatientLink.AnesthesiaRecord.Xhhs1 != null && PatientLink.AnesthesiaRecord.Xhhs1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xhhs1));
                if (a != null) _disCruisingNurseDoctorName += a.TrueName ;
            }
            else
            {
                _disCruisingNurseDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xhhs1) ? "" : ("," + PatientLink.AnesthesiaRecord.Xhhs1);
            }
            if (PatientLink.AnesthesiaRecord.Xhhs2 != null && PatientLink.AnesthesiaRecord.Xhhs2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xhhs2));
                if (a != null) _disCruisingNurseDoctorName += "," + a.TrueName ;
            }
            else
            {
                _disCruisingNurseDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xhhs2) ? "" : ("," + PatientLink.AnesthesiaRecord.Xhhs2);
            }
            if (PatientLink.AnesthesiaRecord.Xhhs3 != null && PatientLink.AnesthesiaRecord.Xhhs3.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xhhs3));
                if (a != null) _disCruisingNurseDoctorName += "," + a.TrueName;
            }
            else
            {
                _disCruisingNurseDoctorName += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xhhs3) ? "" : ("," + PatientLink.AnesthesiaRecord.Xhhs3);
            }
            DisCruisingNurseDoctorName = _disCruisingNurseDoctorName;
        }



        #endregion


        #region Public/ProtectedMethods
        public void Load_page()
        {
            ConvertAnesDoctor();
            ConvertOperDoctor1();
            ConvertNurseDoctor();
            ConvertCruiseNurseDoctor();

        }


        //手术医生控件

        public void OperationTanChu()
        {
            OperationOptCtrl no = new OperationOptCtrl();
            DrugAndEventWindow.Instance.CusContent = no;
            DrugAndEventWindow.Instance.Width = 450;
            DrugAndEventWindow.Instance.Height = 350;
            DrugAndEventWindow.Instance.Title = "手术医生";
            DrugAndEventWindow.Instance.ShowDialog();
            no.KeepAccountModel += (newAccountModelList) =>
            {
                DisoperDoctorName = newAccountModelList;
            };
        }

        //洗手护士控件
        public void NurseTanChu()
        {
            WashNurseCtrl no = new WashNurseCtrl();
            DrugAndEventWindow.Instance.CusContent = no;
            DrugAndEventWindow.Instance.Width = 350;
            DrugAndEventWindow.Instance.Height = 250;
            DrugAndEventWindow.Instance.Title = "洗手护士";
            DrugAndEventWindow.Instance.ShowDialog();
            no.KeepAccountModel += (newAccountModelList) =>
            {
                DisNurseDoctorName = newAccountModelList;
            };
        }



        //巡回护士控件
        public void CruisingNurseTanChu()
        {
            CruiseNurseCtrl no = new CruiseNurseCtrl();
            DrugAndEventWindow.Instance.Width = 350;
            DrugAndEventWindow.Instance.Height = 250;
            DrugAndEventWindow.Instance.CusContent = no;
            DrugAndEventWindow.Instance.Title = "巡回护士";
            DrugAndEventWindow.Instance.ShowDialog();
            no.KeepAccountModel += (newAccountModelList) =>
            {
                DisCruisingNurseDoctorName = newAccountModelList;
            };
        }


        //麻醉医生控件
        public void AnesDoctorTanChu()
        {

            AnesDoctorOpt ado1 = new AnesDoctorOpt();
            DrugAndEventWindow.Instance.CusContent = ado1;
            DrugAndEventWindow.Instance.Width = 450;
            DrugAndEventWindow.Instance.Height = 350;
            DrugAndEventWindow.Instance.Title = "麻醉医生";
            DrugAndEventWindow.Instance.ShowDialog();
            ado1.KeepAccountModel += (newAccountModelList) =>
            {
                DisAnesDoctorName = newAccountModelList;
            };


        }

        //平利县中医院麻醉医生控件
        public void AnesPlzyyDoctorTanChu()
        {

            AnesDoctorOpt ado = new AnesDoctorOpt();
            DrugAndEventWindow.Instance.CusContent = ado;
            DrugAndEventWindow.Instance.Width = 450;
            DrugAndEventWindow.Instance.Height = 350;
            DrugAndEventWindow.Instance.ShowDialog();
            ado.KeepAccountModel += (newAccountModelList) =>
            {
                DisAnesDoctorName = newAccountModelList;
            };
        }
        #endregion


        #region EventHandlers

        #endregion
    }
}
